


    <div class="my_deals_index">
<div class="clear"></div>
<?php
$index->setData($deals, 'Deal');

$index->showFields(array('title',array('listing_id'=>'Listing'),array('published_on'=>'Published'),array('expires'=>'Valid until'),array('deal_status'=>'Status'))); //,array('list_category_id'=>'Category') ,array('discount_type'=>'Discount Type')
$index->sortableFields(array('title','expires','listing_id'));

$index->addColumn('listing_id','showListing');
//$index->addColumn('discount','showDiscount');
$index->addColumn('published_on','showPublishedOn');
//$index->addColumn('list_category_id','showCategory');
//$index->addColumn('deal_status','showDealStatus');

function showListing($record)
{
	$html = ClassRegistry::getObject('view')->loaded['html'];
	if($record['Listing']['title'] == '')
	{
		return "No information";
	}
	return $html->link($record['Listing']['title'],$record['Listing']['viewUrl']);
}
function showCategory($record)
{
	$html = ClassRegistry::getObject('view')->loaded['html'];
	return $html->link($record['ListCategory']['name'],array("plugin"=>null,'controller'=>'listings','action'=>'index','category','category'=>$record['ListCategory']['slug']));
}
//function showDiscount($record)
//{
	//return $record['Deal']['discount'].(($record['Deal']['discount_type'] == Deal::DISCOUNT_TYPE_PERCENT)?" %":"");
//}
function showPublishedOn($record)
{
	return date("Y-m-d", strtotime($record['Deal']['publish_on_date']))." ".$record['Deal']['publish_on_time'];
}


$index->setAction(__('View'), array('action'=>'view', ':Deal.id'));
$index->setAction(__('Edit'), array('action'=>'edit', ':Deal.id'));
$index->setAction(__('Delete'), array('action'=>'delete', ':Deal.id'),$this->helpers,__('Are you sure, you want to delete this record ?'));

/*
$index->setAction(null, null,$this->helpers,false,true,'publish_unpublish');
$index->setAction(null, null,$this->helpers,false,true,'toggle_purchase_link');
function publish_unpublish($model,$record)
{
	if($record[$model]['status'] == Deal::PUBLISH)
	{
		$action['title'] = __('Unpublish');
		$action['url'] = '/deals/deals/changeStatus/'.$record[$model]['id'];
		$action['confirmMessage'] = sprintf(__('Are you sure, you want to unpublish this %s ?'),__($record[$model]['deal_type']));
	} else {
		$action['title'] = __('Publish');
		$action['url'] = '/deals/changeStatus/'.$record[$model]['id'];
	}
	return $action;
}
function toggle_purchase_link($model, $record)
{
	if($record[$model]['deal_type'] == Deal::TYPE_PROMOTION)
	{
		if($record[$model]['purchase_link_status'])
		{
			$action['title'] = __('Deactivate Online Purchase');
			$action['url'] = '/deals/deals/changePurchaseLinkStatus/'.$record[$model]['id'];
			$action['confirmMessage'] = __('Are you sure ?');
		} else {
			$action['title'] = __('Activate Online Purchase');
			$action['url'] = '/deals/deals/changePurchaseLinkStatus/'.$record[$model]['id'];
		}
		return $action;
	} else {
		return false;
	}
}
*/
echo $index->display($deals);
?>
</div>